/***************************************************************************
创建者：华磊
 开始时间：               : 2020.1１.09
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   右侧自定义功能视窗测试用代理类
*                                                                         *
 ***************************************************************************/
#include "rightfundelegate.h"
#include "hmicommondefine.h"
#include "instructionEnum.h"

//#include <QDebug>

RightFunDelegate::RightFunDelegate(RightFun *rightFunIn, GlobalData *globalDataIn,
                                   QObject* parent):QObject(parent)
{
    globalData = globalDataIn;
    rightFun=rightFunIn;

    initConnect();
}

RightFunDelegate::~RightFunDelegate()
{

}

void RightFunDelegate::initConnect()
{
    connect(rightFun,SIGNAL(rightFunEmpty1_signal()),this,SLOT(rightFunEmpty1Slot()));
    connect(rightFun,SIGNAL(rightFunEmpty2_signal()),this,SLOT(rightFunEmpty2Slot()));
    connect(rightFun,SIGNAL(rightFunEmpty3_signal()),this,SLOT(rightFunEmpty3Slot()));

    connect(rightFun,SIGNAL(rightStopRunSignal()),this,SLOT(rightFunStopSlot()));
}

void RightFunDelegate::rightFunEmpty1Slot()
{
    qDebug()<<"rightfun1 shift";

    if(globalData)
    {
//       if(globalData->tryLock(TRYLOCKTIME))
//       {
           if(EM_JOG_COORDINATE_JOINT==globalData->globalCoordinate)
           {
               globalData->jogPageIndex++;
               if(globalData->jogPageIndex*globalData->onePageAxisCount >= globalData->robotAxisCount)
               {
                    globalData->jogPageIndex=0;
               }
               qDebug()<<"rightfun1 shift page"<<globalData->jogPageIndex;

           }
           else
           {
               qDebug()<<"rightfun1 shift coordinate";
//               globalData->isJogControlSecondGroupAxis = false;
//               emit changeJogAxisName_signal(false,globalData->robotAxisCount,0
//                                             ,globalData->onePageAxisCount);
           }

//           globalData->unlock();


//       }
    }
}

void RightFunDelegate::rightFunEmpty2Slot()
{
//    if(globalData)
//    {
//        if(globalData->tryLock(TRYLOCKTIME))
//        {
//            if(globalData->globalCurrentState == ENUM_COMMAND_RUN||globalData->globalCurrentState == ENUM_COMMAND_CEASE)
//            {
//                globalData->unlock();
//                emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前机器正在运行,禁止操作"));
//                return;
//            }
//            globalData->unlock();
//        }
//    }

//    runFlag = true;
    emit rightMoveToPointSignal(EM_CF_DEG_TYPE);//关节 0
}

void RightFunDelegate::rightFunEmpty3Slot()
{
//    if(globalData)
//    {
//        if(globalData->tryLock(TRYLOCKTIME))
//        {
//            if(globalData->globalCurrentState == ENUM_COMMAND_RUN||globalData->globalCurrentState == ENUM_COMMAND_CEASE)
//            {
//                globalData->unlock();
//                emit msgBoxSignal(EM_MSG_BOX_SURE_BTN,tr("提示"),tr("当前机器正在运行,禁止操作"));
//                return;
//            }
//            globalData->unlock();
//        }
//    }

//    runFlag = true;
    emit rightMoveToPointSignal(EM_CF_WORLD_TYPE);//直线 1
}

void RightFunDelegate::rightFunStopSlot()
{
//    if(runFlag)
//    {
//        //qDebug()<<"rightfun4";
        emit rightMoveStopSignal();

//        runFlag = false;
//    }
}

void RightFunDelegate::changeLanguageSlot(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/rightFunDelEnglishLan.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
    rightFun->changeLanguage(language);
}
